import { ElMessage, ElNotification, ElMessageBox } from 'element-plus'

// 简化的消息提示配置
const messageConfig = {
  duration: 3000,
  showClose: true
}

const notificationConfig = {
  duration: 4000,
  position: 'top-right',
  showClose: true
}

// 封装的消息提示方法
export const message = {
  success: (text, options = {}) => {
    return ElMessage.success({
      message: text,
      ...messageConfig,
      ...options
    })
  },
  
  warning: (text, options = {}) => {
    return ElMessage.warning({
      message: text,
      ...messageConfig,
      ...options
    })
  },
  
  error: (text, options = {}) => {
    return ElMessage.error({
      message: text,
      ...messageConfig,
      ...options
    })
  },
  
  info: (text, options = {}) => {
    return ElMessage.info({
      message: text,
      ...messageConfig,
      ...options
    })
  }
}

export const notify = {
  success: (title, message = '', options = {}) => {
    return ElNotification.success({
      title,
      message,
      ...notificationConfig,
      ...options
    })
  },
  
  warning: (title, message = '', options = {}) => {
    return ElNotification.warning({
      title,
      message,
      ...notificationConfig,
      ...options
    })
  },
  
  error: (title, message = '', options = {}) => {
    return ElNotification.error({
      title,
      message,
      ...notificationConfig,
      ...options
    })
  },
  
  info: (title, message = '', options = {}) => {
    return ElNotification.info({
      title,
      message,
      ...notificationConfig,
      ...options
    })
  }
}

// 简化的确认对话框
export const confirm = {
  // 删除确认
  delete: (title, message = '此操作不可逆，请谨慎操作！') => {
    return ElMessageBox.confirm(
      message,
      title,
      {
        confirmButtonText: '确定删除',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }
    )
  },
  
  // 普通确认
  normal: (title, message = '确定要执行此操作吗？') => {
    return ElMessageBox.confirm(
      message,
      title,
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'info',
        center: true
      }
    )
  },
  
  // 警告确认
  warning: (title, message = '请确认您的操作！') => {
    return ElMessageBox.confirm(
      message,
      title,
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }
    )
  }
}

// 统一的操作反馈
export const feedback = {
  // 操作成功
  success: (operation = '操作') => {
    return message.success(`${operation}成功！`)
  },
  
  // 操作失败
  error: (operation = '操作', reason = '请重试') => {
    return message.error(`${operation}失败，${reason}`)
  },
  
  // 删除成功
  deleted: (count = 1) => {
    return message.success(`成功删除 ${count} 项`)
  },
  
  // 网络错误
  networkError: () => {
    return message.error('网络连接失败，请检查网络连接')
  }
}

// 客服信息通知
export const showCustomerService = () => {
  return notify.info(
    '客服信息',
    `客服电话：400-888-8888
工作时间：9:00-18:00
邮箱：service@pcbcsm.com
在线客服：工作日全天候服务`,
    { duration: 6000 }
  )
}

// 批量操作确认
export const batchConfirm = (operation, count, itemName = '项') => {
  return confirm.warning(
    `批量${operation}`,
    `确定要${operation}选中的 ${count} ${itemName}吗？`
  )
}

// 导出所有功能
export default {
  message,
  notify,
  confirm,
  feedback,
  showCustomerService,
  batchConfirm
} 